/**
 * 
 */
package com.xingfume.jedis;

import java.io.FileInputStream;
import java.util.Properties;
import java.util.ResourceBundle;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/** 
 * @author kevin weizhikai.ai@gmail.com: 
 * @version 创建时间：2015年5月22日 上午10:43:13 
 * 项目名称：articles-manager-system
 * 项目名称：JedisPoolInit
 */
/**
 * @author kevin
 *
 */
public class JedisPoolInit {
	public static JedisPool pool;
	
	public JedisPoolInit(){};
	
	public static JedisPool getJedisPool()
	{
		if(null == pool)
		{
			ResourceBundle bundle = ResourceBundle.getBundle("redis");
			if (bundle == null) {
				throw new IllegalArgumentException("[redis.properties] is not found!");
			}
			JedisPoolConfig config = new JedisPoolConfig();
			config.setMaxTotal(Integer.parseInt(bundle.getString("redis.pool.maxActive")));
			config.setMaxIdle(Integer.parseInt(bundle.getString("redis.pool.maxActive")));
			config.setMaxWaitMillis(Long.parseLong(bundle.getString("redis.pool.maxActive")));
			config.setTestOnBorrow(Boolean.parseBoolean(bundle.getString("redis.pool.maxActive")));
			config.setTestOnReturn(Boolean.parseBoolean(bundle.getString("redis.pool.maxActive")));
			pool = new JedisPool(config, bundle.getString("redis.ip"), Integer.valueOf(bundle.getString("redis.port")));
		}
		return pool;
	}
	
	public static void main(String[] args) {
			Jedis jedis = getJedisPool().getResource();
			jedis.set("aaa", "111");
			System.out.println(jedis.get("aaa"));
	}
}
